#include <iostream>
using namespace std;

struct List{
	int data;
	struct List *next;
};

void Create(List *&A, List *&B);
void Output(List *A);
void bing(List *A, List *B, List *&C);
void jiao(List *A, List *B, List *&D);
void cha(List *A, List *D, List *&E);
int main(){
	List *A, *B, *C ,*D, *E;
	Create(A, B);
	bing(A, B, C);
	jiao(A, B, D);
	cha(A, D, E);
}

void Create(List *&A, List *&B){
	List *s, *r;
	A = new List;
	r = A;
	int n1, n2, x;
	cin >> n1 >> n2;
	while(n1--){
		cin >> x;
		s = new List;
		s->data = x;
		r->next = s;
		r = s;
	}
	r->next = NULL;
	
	B = new List;
	r = B;
	while(n2--){
		cin >> x;
		s = new List;
		s->data = x;
		r->next = s;
		r = s;
	}
	r->next = NULL;
}
void Output(List *A){
	List *p = A->next;
	while(p!=NULL){
		cout << p->data << " ";
		p = p->next;
	}
	cout <<endl;
}
void bing(List *A, List *B, List *&C){
	C = new List;
	int k = 0;
	List *p = A->next, *s, *r, *q;
	r = C;
	while(p!=NULL){
		s = new List;
		k++;
		s->data = p->data;
		r->next = s;
		r = s;
		p = p->next;
	} 
	p = A->next; q = B->next;
	int j = 0;
	while(q!=NULL){
		j = 0;
		p = A->next;
		while(p!=NULL){
			if(p->data == q->data)
				j = 1;	
			p = p->next;
		}
		if(!j){
			s = new List;
			k++;
			s->data = q->data;
			r->next = s;
			r = s;
		}
		q = q->next;
	}
	r->next = NULL;
	cout << k << " ";
	Output(C);
}
void jiao(List *A, List *B, List *&D){
	D = new List;
	List *p = A->next, *q = B->next, *s, *r;
	int k = 0;
	r = D;
	while(p!=NULL){
		q = B->next;
		while(q!=NULL){
			if(p->data == q->data){
				s = new List;
				k++;
				s->data = q->data;
				r->next = s;
				r = s;
			}
			q = q->next;
		}
		p = p->next;
	}
	r->next = NULL; 
	cout << k << " ";
	Output(D);
}
void cha(List *A, List *D, List *&E){
	E = new List;
	List *p = A->next, *q = D->next, *s, *r;
	int k = 0;
	r = E;
	int j = 0;
	while(p!=NULL){
		j = 0;
		q = D->next;
		while(q!=NULL){
			if(p->data == q->data)
				j = 1;
			q = q->next;
		}
		if(!j){
			s = new List;
			k++;
			s->data = p->data;
			r->next = s;
			r = s;
		}
		p = p->next;
	}
	r->next = NULL; 
	cout << k << " ";
	Output(E);
}

